package com.wdy.service.impl;

import java.util.List;

import com.wdy.dao.BuildingDao;
import com.wdy.po.Building;
import com.wdy.po.Page;
import com.wdy.po.Result;
import com.wdy.service.BuildingManager;
import com.wdy.util.PageUtil;

public class BuildingManagerImpl implements BuildingManager {

	private BuildingDao buildingDao;
	
	public void setBuildingDao(BuildingDao buildingDao) {
		this.buildingDao = buildingDao;
	}

	
	public void saveBuilding(Building building) {
		buildingDao.save(building);
	}

	
	public void removeBuilding(Building building) {
		buildingDao.delete(building);
	}

	
	public void updateBuilding(Building building) {
		buildingDao.attachDirty(building);
	}

	
	public Building getBuilding(Integer id) {
		return buildingDao.findById(id);
	}


	public List<Building> listAll() {
		return buildingDao.findAll();
	}

	
	public List<Building> findByExample(Building building) {
		return buildingDao.findByExample(building);
	}


	public List<Building> findByAddress(String value) {
		return buildingDao.findByAddress(value);
	}
	

	public Result listBuilding(Page page) {
		int totalRecords = this.buildingDao.getBuildingCount();
		page = PageUtil.createPage(page, totalRecords);
		List<Building> buildings = (List<Building>)this.buildingDao.getBuildingByPage(page);     
		return new Result(page, buildings);
	}
}
